package com.chixing.day11_exception;

public class ExceptionDemo {
    public static void main(String[] args) {
        /*try {
            System.out.println("try111");
            Class.forName("com.chixing.day11_exception.ExceptionDemo");//报异常 new ClassNotFoundException();
            System.out.println("try222");
        } catch (ClassNotFoundException e) {
            System.out.println("chatx222");
            e.printStackTrace();
        }

        System.out.println("xxxxxxxxxx");

        try {
            System.out.println("try333");
            ExceptionDemo.class.getField("").get(null);
            System.out.println("try444");
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }

        System.out.println("xxxxxxxxxx");*/


        //finally:


        try{
            //捕捉可能出现异常的代码
        }catch(Exception e){
            //处理异常的代码
        }finally{
            //作用：释放内存，节省空间（流的关闭，数据库连接关闭等）
            //语法：无论是否有异常，finally一定会执行
        }
        System.out.println("返回值为"+fun1());
    }


    /*
     * return：结束方法
     * 1. return  - finally(方法返回值为10，finally a = 20)
     *
     */
    public static int fun1(){
        int a=10;
        try{
            Class.forName("com.chixing.day11_exception.ExceptionDemo");
            System.out.println("return，a="+a);
            return a;
        }catch(ClassNotFoundException e){
            return -1;
        }finally{
            System.out.println("finally....");
            a=20;
            System.out.println("finally，a="+a);
        }
    }
}
